package com.z.action;

import com.z.base.BaseAction;
import com.z.service.RegisterService;
import com.z.vo.RegisterForm;

@SuppressWarnings("serial")
public class RegisterAction extends BaseAction {
	private RegisterForm registerForm=new RegisterForm();
	
	@Override
	public Object getModel() {
		return registerForm;
	}
	
	public String execute(){
		return SUCCESS;
	}
	
	public String add(){
		int value=RegisterService.getInstance().register(registerForm.getAccount());
		if(value==0){
			return "add_ok";
		}
		return "add_fail";
	}
	
	public String registerManager(){
		if(RegisterService.getInstance().checkManagerExisted()==1){
			return "manager_existed";
		}
		return "manager";
	}
	
	public String saveManager(){
		int value=RegisterService.getInstance().addManager(registerForm.getAccount());
		if(value==0){
			return "add_manager_ok";
		}
		return "add_manager_fail";
	}
	
	public String checkAccountAvailable(){
		boolean b=RegisterService.getInstance().checkAccountAvailable(registerForm.getLoginName());
		String result=b?"1":"0";
		return renderJson(result);
	}
	
	public String queryName(){
		String s=RegisterService.getInstance().findName(registerForm.getId());
		return renderText(s==null?"UNKNOW":s);
	}
}
